#ifndef __chain_plane__
#define __chain_plane__
if(token.Matches(_("p_plane"))&&(T.GetCount()==5))
{
    IsNotExtFunc = false;

    int IM = int(calc(T[0]));
    double  A = -90*DegToRad; //(calc(T[0])-90)*DegToRad;
    double  R = calc(T[1]);
    double  Z = calc(T[2]);
    double SR = calc(T[3]);      //sivu suojus
    double Ae = calc(T[4]);

    double TR = I[tNum].H.x;

    mPointArray p;

    mPoint P1 = mP(0,0,0);
    mPoint P2 = P1.GetFromPoint(A,1);
    mPoint P3 = P1.GetFromPoint(A,1);
    mPoint M1 = P1.GetFromPoint(A-(PI/2),-0.1);
    mPoint M2 = P1.GetFromPoint(A-(PI/2),-TR);   //TERÄN puolikas?
    mPoint T1,T2;

    CODE << wxString::Format(wxT("#26=%1.3f\n"),Z);

    while(true)
    {
        P1+=M1;
        P2+=M1;
        p = I[IM].IntImgRay(P1,P2);
        if(p.size()==0)break;
        p.Clear();
    }

    M1 = mP(0,0,0).GetFromPoint(A-(PI/2),Ae); //SIIRTO ARVO
    while(true)
    {
        P1+=M1;
        P2+=M1;
        p.Clear();
        p.Add(I[IM].IntImgRay(P1,P2) ,true );                //ETU REUNA
        p.Add(I[IM].IntImgRay(P1+M2,P2+M2),true );          //Terän keskusta
        p.Add(I[IM].IntImgRay(P1+M2+M2,P2+M2+M2),true );    //loppu reuna

        //p.SortX();
        p.SortY();
        if(p.size()<2)break;

        //FIND EDGE...
        T1 = mP( P1.x+M2.x , p.H.y);
        T2 = mP( P1.x+M2.x , p.L.y);

        while( I[IM].Distance(T2) < (I[startToolPos+tNum].H.x+SR))
        {
            T2+=P3;
        }
         while( I[IM].Distance(T1) < (I[startToolPos+tNum].H.x+SR))
        {
            T1-=P3;
        }
        //FOR debug
        CODE << wxString::Format(wxT("G0X%1.3fY%1.3f\n"),T1.x,T1.y);
        CODE << wxString::Format(wxT("G0Z#26\n"));
        CODE << wxString::Format(wxT("G1X%1.3fY%1.3f\n"),T2.x,T2.y);
        CODE << wxString::Format(wxT("G0Z%1.3f\n"),R);

        p.Clear();

    }


    continue;
}

//OLD
if(token.Matches(_("p_plane"))&&(T.GetCount()==10))
{
    IsNotExtFunc = false;

    double Dc = I[startToolPos+tNum].H.x/2;

    double A = calc(T[0]);
    double X = calc(T[1]);
    double Y = calc(T[2]);
    double R = calc(T[3]);
    double P = calc(T[4]);
    double Z = calc(T[5]);

    double W = calc(T[6])/2+Dc+5.0;
    double H = calc(T[7])-Dc;
    double Ae = calc(T[8]);
    double Ap = calc(T[9]);

    double x = Ae-Dc;

    wxString buffer;

    while(true)
    {
        mPointArray ma;
        if(x>H)x=H;
        ma.Add(mP(x,-W));
        ma.Add(mP(x, W));

        //ma.Translate( 0 , y+(sy/2) , 0.0);
        ma.RotateZ((A*DegToRad));
        ma.Translate(mP(X,Y));

        double z=P;
        while(true)
        {
            z=z-Ap;
            if(z<Z)z=Z;
            buffer.Printf(_("G0X%1.3fY%1.3f\n"),   ma.at(0).x   ,  ma.at(0).y  );CODE << buffer;
            buffer.Printf(_("Z%1.3f\n"),z);                                        CODE << buffer;
            buffer.Printf(_("G1X%1.3fY%1.3f\n"),   ma.at(1).x   ,   ma.at(1).y );CODE << buffer;
            buffer.Printf(_("G0Z%1.3f\n"),   R );                                  CODE << buffer;
            if(AER(z,Z,0.0001))break;
        }
        if(AER(x,H,0.0001))break;
        x=x+Ae;
        ma.Clear();
    }

    CODE << _("\n");
    continue;
}
#else
INFO << _("p_plane(I,R,Z,SR,Ae)<BR>");
if(token.Matches(_("p_plane(*,*,*,*,*)")))
{
    INFO = _("<b>p_plane</b>(I,R,Z,SR,Ae)<BR><BR>");
    INFO << _("I = Image<BR>");
    INFO << _("R = Safe height<BR>");
    INFO << _("Z = Deep of cut<BR>");
    INFO << _("SR = XY safety distance<BR>");
    INFO << _("Ae = Side cut depth<BR>");

    INFO << _("<b>description:</b><BR>");
    INFO << _("plaa plaa plaa<BR>");
    INFO << _("<BR>");
    INFO << _("<BR>");
    return true;
}
#endif
